package cn.dmrliu.edu.publish.bean;

import cn.dmrliu.edu.publish.util.DoubleUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

@Data
@AllArgsConstructor
public class ToolExamPaperStats {
    // 试卷id
    String paperId;
    // 试卷名称
    String paperName;
    // 考试人数
    Long userCt;
    // 考试总分
    Double scoreSum;
    // 考试总时长
    Long durSum;

    // 求平均分
    public Double avgScore() {
        return DoubleUtil.toTwo((double) scoreSum / (double) userCt);
    }

    // 求平均时长
    public Double avgDur() {
        return
                DoubleUtil.toTwo((double) durSum / (double) userCt);
    }

    @Override
    public String toString() {
        return "{" +
                "   \"paperId\": \"" + this.paperId + "\",\n" +
                "   \"paperName\": \"" + StringUtils.replace(this.paperName, "\\", "_") + "\",\n" +
                "   \"userCt\": \"" + this.userCt + "\",\n" +
                "   \"avgScore\": \"" + this.avgScore() + "\",\n" +
                "   \"avgDur\": \"" + this.avgDur() + "\"\n" +
                "}";
    }
}
